package com.leiyuee.principle;

/**
 * 接口隔离原则:一个类对另外一个类的依赖应该建立在最小的接口上
 */
public class Segragation {
    public static void main(String[] args) {

    }
}

interface Interface1 {
    void operation1();
}

interface Interface2 {
    void operation2();

    void operation3();
}

interface Interface3 {
    void operation4();

    void operation5();
}

class A { // A
    public void depend1(Interface1 i) {
        i.operation1();
    }

    public void depend2(Interface2 i) {
        i.operation2();
    }

    public void depend3(Interface2 i) {
        i.operation3();
    }
}

class C { // A
    public void depend1(Interface1 i) {
        i.operation1();
    }

    public void depend2(Interface3 i) {
        i.operation4();
    }

    public void depend3(Interface3 i) {
        i.operation5();
    }
}


//--------------------------------------
class B implements Interface1, Interface2 {

    @Override
    public void operation1() {
        System.out.println("B 实现了1");
    }

    @Override
    public void operation2() {
        System.out.println("B 实现了2");
    }

    @Override
    public void operation3() {
        System.out.println("B 实现了3");
    }

}


class D implements Interface1, Interface3 {

    @Override
    public void operation1() {
        System.out.println("D 实现了1");
    }

    @Override
    public void operation4() {
        System.out.println("D 实现了4");
    }

    @Override
    public void operation5() {
        System.out.println("D 实现了5");
    }
}